# -*- coding: utf-8 -*-

from core.viewset import CustomModelViewSet
from core.response import JsonResponse
from apps.rms.models import ProtocolType
from rest_framework.decorators import action
from apps.rms.protocol.serializers import *
from apps.rms.protocol.resources import *
from apps.rms.protocol.filters import *


class ProtocolTypeViewSet(CustomModelViewSet):
    """
    协议类型管理接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """

    queryset = ProtocolType.objects.all()
    serializer_class = ProtocolTypeSerializer
    filterset_class = ProtocolTypeFilterSet
    import_resources = ProtocolTypeResouces
    export_resources = ProtocolTypeResouces

    @action(detail=False, methods=["GET"])
    def treeselect(self, request, *args, **kwargs):
        queryset = ProtocolType.objects.all()
        serializer = ProtocolTreeSelectSerializer(queryset, many=True, request=request)
        return JsonResponse(data=serializer.data, msg="获取成功")


class ProtocolFieldViewSet(CustomModelViewSet):
    """
    协议字段接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """

    queryset = ProtocolField.objects.all()
    serializer_class = ProtocolFieldSerializer
    filterset_class = ProtocolFieldFilterSet
    import_resources = ProtocolFieldResouces
    export_resources = ProtocolFieldResouces
